/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tetris.model.spel;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.swing.JLabel;
import javax.swing.Timer;
import tetris.view.ScorePaneel;

/**
 *
 * @author Pieter Hens
 */
public class SpeelTijd extends JLabel implements ActionListener {

    private ScorePaneel hoofdframe;
    private int uren,  minuten,  seconden;
    private AePlayWave klik;
    private Timer tim;
    private boolean pauze;
    // private JLabel klok;
    

    public SpeelTijd(ScorePaneel hfdframe) {
        setLayout(new FlowLayout());
        Font font = new Font("Serif", Font.PLAIN, 30);
        setFont(font);
        hoofdframe = hfdframe;
        uren = 0;
        minuten = 0;
        seconden = 0;
        klik = new AePlayWave("click.wav");
        
        teken();
        
         tim = new Timer(1000, (ActionListener) this);
        tim.start();
        


    }

    public void actionPerformed(ActionEvent arg0) {
        seconden++;
        teken();
        klik.run();
    }

    public void teken() {
        if (seconden == 60) {
            seconden = 0;
            minuten++;
            if (minuten == 60) {
                minuten = 0;
                uren++;

            }
        }
        NumberFormat formatter = new DecimalFormat("00");
        this.setText(formatter.format(uren) + ":" + formatter.format(minuten) + ":" + formatter.format(seconden));
    }
    
     public void pauze () {
        if (! pauze){
            tim.stop();
            pauze = true;
        } else {
            tim.start();
            pauze = false;
        }
    }

    
    
}
